package mark;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.Toast;
import java.util.ArrayList;
import org.jaaksi.commondemo.R;

/**
 * 创建时间：2018年02月08日15:39 <br>
 * 作者：fuchaoyang <br>
 * 描述：
 */

public class TestMarkActivity extends Activity
  implements AbsListView.OnScrollListener, View.OnScrollChangeListener {
  View attachview; // 980
  ListView mListView;
  private StickyMark mStickyMark;
  private MyAdapter mAdapter;
  // 获取ListView中的view
  private ScrollView mScrollView;

  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_testmark);
    mListView = (ListView) findViewById(R.id.listview);
    mListView.setOnScrollListener(this);
    attachview = findViewById(R.id.attachview);
    mScrollView = (ScrollView) findViewById(R.id.scrollView);
    mScrollView.setOnScrollChangeListener(this); // 23
    attachview.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        Toast.makeText(TestMarkActivity.this, "ok", 1).show();
      }
    });
    mStickyMark = new StickyMark(this);
    mStickyMark.setMarkView(getLayoutInflater().inflate(R.layout.popup_mark, null));
    mStickyMark.attach(attachview);

    // listview中的mark
    mAdapter = new MyAdapter(this);
    ArrayList<String> infos = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
      if (i == 5) {
        infos.add("vr");
      } else {
        infos.add(String.format("%02d数据", i));
      }
    }
    mListView.setAdapter(mAdapter);
    mAdapter.setDatas(infos);
  }

  @Override public void onScrollStateChanged(AbsListView view, int scrollState) {

  }

  @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
    int totalItemCount) {
    if (mAdapter != null) mAdapter.onScroll();
  }

  @Override
  public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
    mStickyMark.attach(attachview);
  }
}
